<#-- @ftlvariable name="entity" type="com.xci.edu.core.entity.ExamPaper" -->
<#include "/sys/_layout.ftl">
<#assign allowInsert=sysWeb.auth("background.examPaper.insert")/>
<#assign allowUpdate=sysWeb.auth("background.examPaper.update")/>
<#assign allowDelete=sysWeb.auth("background.examPaper.delete")/>
<#assign allowExport=sysWeb.auth("background.examPaper.export")/>
<!doctype html>
<html>
<head>
    <@pageHeader/>
</head>
<body>
<@pageLoading/>
<div id="gridtoolbar">
    <form id="gridform" class="jxlayout-form form-inline jxform">
        <div class="form-group">
            <input name="name" class="form-control w-250px" placeholder="请输入试卷名称关键字" autocomplete="off">
        </div>
        <div class="form-group">
            <select name="status" class="jxselect form-control" data-select-submit="true" data-allow-clear="false" data-width="110">
                ${web.statusSelectOptions()}
            </select>
        </div>
        <button class="btn btn-primary ml-5" type="submit">
            <i class="fa fa-search"></i> 查询
        </button>
        <div class="btn-group">
            <@echo test=allowInsert>
            <a class="btn btn-default" onclick="curd.createData()">
                <i class="icon-plus"></i> 新建
            </a>
        </@echo>
        <@echo test=allowUpdate>
            <a class="btn btn-default" onclick="curd.editData()">
                <i class="icon-pencil"></i> 编辑
            </a>
        </@echo>
        <@echo test=allowDelete>
            <a class="btn btn-default" onclick="curd.deleteData()">
                <i class="icon-trash"></i> 删除
            </a>
        </@echo>
        <@echo test=allowExport>
            <a class="btn btn-default" onclick="curd.exportData()">
                <i class="icon-share-alt"></i> 导出
            </a>
        </@echo>
        </div>
    </form>
</div>
<table id="grid" data-options="form:'#gridform',toolbar:'#gridtoolbar'">
    <thead>
    <tr>
        <th data-options="field:'ck',checkbox:true"></th>
        <th data-options="title:'试卷名称',field:'name',width:200,align:'left',sortable: false"></th>
        <th data-options="title:'科目名称',field:'eduCategoryName',width:200,align:'left',sortable: false"></th>
        <th data-options="title:'试卷类型',field:'paperCategoryName',width:100,align:'left',sortable: false"></th>
        <th data-options="title:'试卷总分',field:'totalScore',width:100,align:'left',sortable: false"></th>
        <th data-options="title:'考试时长',field:'totalDuration',width:100,align:'left',sortable: false"></th>
        <th data-options="title:'及格分数',field:'passScore',width:100,align:'left',sortable: false"></th>
        <th data-options="title:'试卷展示',field:'showModeName',width:200,align:'left',sortable: false"></th>
        <th data-options="title:'状态',field:'status',width:200,align:'left',sortable: false,formatter:jx.gf.status"></th>
        <th data-options="title:'备注',field:'remark',width:200,align:'left',sortable: false"></th>
        <th data-options="title:'操作',field:'id',width:200,align:'left',formatter: formatCommand"></th>
    </tr>
    </thead>
</table>
<@pageFooter/>
<script type="text/html" id="cmd_tpl">
    <div style="margin: 0 5px">
            <a class="cmd-edit" data-id="{0}"><span class="label label-info">添加试题</span></a>

    </div>
</script>
<script>
    function formatCommand(v,row) {
        if(row.paperCategory==1){
            return jx.formatString($('#cmd_tpl').html(), v);
        }
    }
    jx.ready(function () {
        window.curd = new jx.GridCurd('#grid', {
            title: '试卷信息',
            dialogWidth: '500px',
            dialogHeight: '600px',
            api: {
                grid: '/background/examPaper/grid',
                create: '/background/examPaper/create',
                edit: '/background/examPaper/edit',
                delete: '/background/examPaper/delete',
                details: '/background/examPaper/details',
                status: '/background/examPaper/status',
                export: '/background/examPaper/export',
                createDetails: '/background/examPaper/createDetails'
            },
            onInit: function (instance) {
                //状态事件
                instance.gridPanel.on('click', '.gridstatus', function () {
                    instance.setStatusDataById($(this).data('id'), $(this).data('val') == '1' ? 0 : 1);
                });
                //添加试题
                instance.gridPanel.on('click', '.cmd-edit', function () {
                    var row = curd.gridInstance.getSelected();
                    var id = row.id;
                    jx.dialog({
                        url: jx.url(curd.api.createDetails),
                        title: '添加试题',
                        width: '80%',
                        height: '80%',
                        params: {id: id}
                    });
                    // alert($(this).data('id'))
                });
            }
        });
    });
</script>
</body>
</html>